//
//  AppNetworkingManager+Login.m
//  OANetworkManager_Example
//
//  Created by Guo Rui on 2018/2/1.
//  Copyright © 2018年 GuoRui. All rights reserved.
//

#import "AppNetworkingManager+Login.h"
#import "NSString+SHA_1.h"

@implementation AppNetworkingManager (Login)

+ (AppBaseRequest *)loginWithName:(NSString *)userName password:(NSString *)password completion:(OANetworkingObjectBlock)completion
{
    return [self startRequestWithParams:@{ @"loginName": userName, @"password": password }
                                   path:@"login"
                     responseObjectPath:@"data"
                  popoverProgressString:nil
               handleErrorAutomatically:OANETWORKMANAGERSHOWHUD
                          responseBlock:^(id response, NSError *error) {
        
                              if (error == nil) {
                                  [[NSUserDefaults standardUserDefaults]setValue:@{@"loginName" : userName,
                                                                                   @"userId" : [[response objectForKey:@"userId"] stringValue]
                                                                                   }
                                                                          forKey:OANETWORKMANAGERUSER_KEY];
                                  [[NSUserDefaults standardUserDefaults] synchronize];
                              }
        if (completion) {
            completion(response, error);
        }
        
    }];
}

@end
